package com.planet.api;

import com.planet.facade.YhcclrBiz;
import com.planet.query.YhcclrQuery;
import com.planet.utils.global.ExceptionHandle;
import com.planet.utils.global.Result;
import com.planet.utils.global.ResultUtil;
import com.planet.vo.YhcclrVO;
import io.swagger.annotations.ApiParam;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by jiayazi on 17/11/13.
 */
@RestController
@RequestMapping("/check")
public class CheckAPI {
    private static final Logger LOGGER = LogManager.getLogger(CheckAPI.class);

    @Autowired
    private ExceptionHandle exceptionHandle;
    @Autowired
    private YhcclrBiz yhcclrBiz;


    /**
     * 抽查插入
     * @param yhcclrQuery 用户Id
     * @return
     */
    @GetMapping("/insertCheckInfo")
    public Result insertCheckInfo(@ApiParam("插入信息") @RequestBody YhcclrQuery yhcclrQuery){

        //默认结果是成功的
        Result result = ResultUtil.success();
        try {
            int state = yhcclrBiz.insertCheckInfo(yhcclrQuery);
            result =  ResultUtil.success(state);

        }catch (Exception e){
            //调用异常工具类，统一处理异常
            result =  exceptionHandle.exceptionGet(e);
        }
        return result;
    }


    /**
     * 根据编号查看抽查情况
     * @param tarchId 垃圾桶编号Id
     * @return
     */
    @GetMapping("/getCheckInfo")
    public Result getCheckInfo(@ApiParam("垃圾桶编号Id") @RequestParam String tarchId){

        //默认结果是成功的
        Result result = ResultUtil.success();
        try {
            YhcclrVO yhcclrVO = yhcclrBiz.getCheckInfo(tarchId);
            result =  ResultUtil.success(yhcclrVO);

        }catch (Exception e){
            //调用异常工具类，统一处理异常
            result =  exceptionHandle.exceptionGet(e);
        }
        return result;
    }

}
